using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Ras2ClassLib.Common.Data;

namespace Ras2ClassLib
{
	public class Lag : IDataItem
	{
		private int m_nID;
		private string m_strName;
		private int m_GPerformersID;
		private string m_strMp3Path;
		private string m_strDescription;
		private string m_strlgPerformersName;
    

		public Lag()
		{
		}
  
		public int ID
		{
			get { return m_nID; }
			set { m_nID = value; }
		}

		public string Name
		{
			get { return m_strName; }
			set { m_strName = value; }
		}

		public int PerformersID
		{
			get { return m_GPerformersID; }
			set { m_GPerformersID = value; }
		}

		public string Mp3Path
		{
			get { return m_strMp3Path; }
			set { m_strMp3Path = value; }
		}

		public string Description
		{
			get { return m_strDescription; }
			set { m_strDescription = value; }
		}

		public string PerformersName
		{
			get { return m_strlgPerformersName; }
			set { m_strlgPerformersName = value; }
		}

		public override string ToString()
		{
			return m_strName;
		}

		#region IDataList implementation
        public void Load(IDataReader reader)
        {
            m_nID = Convert.ToInt32(reader["LagID"]);
            m_strName = reader["LagNafn"].ToString();
            m_GPerformersID = Convert.ToInt32(reader["fl.FlytjandiID"]);
            m_strMp3Path = reader["LagMP3Path"].ToString();
            m_strDescription = reader["LagLysing"].ToString();
			m_strlgPerformersName = reader["FlytjandiNafn"].ToString();
        }
		#endregion

		public TableDescription GetTable()
		{
			ColumnDescription[] columns = 
			{
				new ColumnDescription( "LagID", this.ID, DbType.Int32, true ),
				new ColumnDescription( "LagNafn", this.Name, DbType.String ),
				new ColumnDescription( "LagMP3Path", this.Mp3Path, DbType.String ),
				new ColumnDescription( "LagLysing", this.Description, DbType.String ),
                new ColumnDescription( "FlytjandiID", this.PerformersID, DbType.Int32, true )
			};
			return new TableDescription("Lag", columns);
		}
	}


	public class LagSorter : IComparer<Lag>
	{
		#region Member variables
		private String m_strOrderBy;
		#endregion

		#region Constructors
		public LagSorter(String strOrderBy)
		{
			m_strOrderBy = strOrderBy;
		}
		#endregion

		#region IComparer implementation
		public int Compare(Lag x, Lag y)
		{
			switch (m_strOrderBy)
			{
                case "ID":
                    return x.ID.CompareTo(y.ID);
				case "Name":
					return x.Name.CompareTo(y.Name);
				case "Mp3Path":
					return x.Mp3Path.CompareTo(y.Mp3Path);
				case "Description":
					return x.Description.CompareTo(y.Description);
			}

			return 0;
		}
		#endregion
	}

	public class LagCollection : DataList<Lag>
	{
		#region Public functions
		public void Sort(String strOrderBy)
		{
			LagSorter sorter = new LagSorter(strOrderBy);
			base.Sort(sorter);
		}
		#endregion
	}
}